/*************************************************************************
 *
 * $Id: dataflash.h 126 2007-02-10 14:57:23Z alpov $
 * 
 *************************************************************************/         

#ifndef _DATAFLASH_H
#define _DATAFLASH_H

#define DF_CS_toggle()      { DF_CS_inactive(); DF_CS_active(); }


extern unsigned char PageBits;
extern unsigned int PageSize;
extern unsigned int PageSizeNorm;
extern unsigned int Pages;

extern void DF_SPI_init(void);
extern unsigned char DF_SPI_RW(unsigned char output);

#define Page_To_Buffer(x, y)        DF_Access(x, y)
#define Buffer_To_Page(x, y)        DF_Access(x, y)
#define Page_Erase(x)               DF_Access(PageErase, x)
#define Block_Erase(x)              DF_Access(BlockErase, x)
extern void DF_Access(unsigned char OpCode, unsigned int PageAdr);
#define FlashToBuf1Transfer         0x53    // Main memory page to buffer 1 transfer
#define FlashToBuf2Transfer         0x55    // Main memory page to buffer 2 transfer
#define Buf1ToFlashWE               0x83    // Buffer 1 to main memory page program with built-in erase
#define Buf2ToFlashWE               0x86    // Buffer 2 to main memory page program with built-in erase
#define Buf1ToFlash                 0x88    // Buffer 1 to main memory page program without built-in erase
#define Buf2ToFlash                 0x89    // Buffer 2 to main memory page program without built-in erase
#define PageErase                   0x81    // Page erase
#define BlockErase                  0x50    // Block erase

#define StatusReg                   0x57    // Status register
extern unsigned char Read_DF_status(void);

#define Buf1Read                    0x54    // Buffer 1 read
#define Buf2Read                    0x56    // Buffer 2 read
extern void Buffer_Read(unsigned char OpCode, unsigned int IntPageAdr, unsigned int No_of_bytes, char *BufferPtr);

#define Buf1Write                   0x84    // Buffer 1 write
#define Buf2Write                   0x87    // Buffer 2 write
extern void Buffer_Write(unsigned char OpCode, unsigned int IntPageAdr, unsigned int No_of_bytes, char *BufferPtr);
extern void Buffer_Fill(unsigned char OpCode, unsigned char Data);

#define FlashToBuf1Compare          0x60    // Main memory page to buffer 1 compare
#define FlashToBuf2Compare          0x61    // Main memory page to buffer 2 compare
extern unsigned char Page_Buffer_Compare(unsigned char OpCode, unsigned int PageAdr);

// ostatni
#define FlashPageRead               0x52    // Main memory page read
#define AutoPageReWrBuf1            0x58    // Auto page rewrite through buffer 1
#define AutoPageReWrBuf2            0x59    // Auto page rewrite through buffer 2
#define ContArrayRead               0x68    // Continuous Array Read (Note : Only A/B-parts supported)
#define FlashProgBuf1               0x82    // Main memory page program through buffer 1
#define FlashProgBuf2               0x85    // Main memory page program through buffer 2

#endif
